#ifdef GrandCPU2012EWW
 #ifndef SetSystemH
  #define SetSystemH
  
 #include "PrimitivesSystem.h" 


/****************************************************************************************************/
/*                                S Y S T E M    C L K    S E T I N G                               */
/****************************************************************************************************/
  #define CLKsrc        ( OSCsrc )     //CLK source
  #define myOSCfreq      12000000      //Hz, main oscillator frequince
  #define myPLLfreq     ( myOSCfreq )  //Hz, PLL output frequince
  #define myCCLKfreq    ( myPLLfreq )  //Hz, CPU frequince

/*                    ! ! !  D o n ' t    c h a n g e    n e x t   l i n e s  ! ! !                 */
     #if   CLKsrc == OSCsrc
                             #define CLKfreq  ( myOSCfreq )
       #elif CLKsrc == RTCsrc
                             #define CLKfreq  ( RTCfreq )
       #else
                             #define CLKfreq  ( IRCfreq )
     #endif
/*                    ! ! !  D o n ' t    c h a n g e    n e x t   l i n e s  ! ! !                 */
     #define pllMulFact    ( myPLLfreq/CLKfreq )
     #if   pllMulFact < 2
                             #define PLLmode    0
                             #define PLLfreq  ( CLKfreq )

       #else
                             #define PLLmode    1
                             #define PLLfreq  ( CLKfreq*pllMulFact )
                             #include "pllCalc.h"
     #endif
/*                    ! ! !  D o n ' t    c h a n g e    n e x t   l i n e s  ! ! !                 */
     #define cpuDivFact    ( PLLfreq/myCCLKfreq )
     #if   cpuDivFact%2
                             #define CCLKCFGdef  ( cpuDivFact )//CCLK frequience will be lower
       #else
                             #define CCLKCFGdef  ( cpuDivFact-1 )//CCLK frequience good
     #endif
     #define CCLKfreq      ( PLLfreq/(CCLKCFGdef+1) )  //Hz, real CPU frequince
/*                    ! ! !  D o n ' t    c h a n g e    n e x t   l i n e s  ! ! !                 */
     #define PCLK1         ( CCLKfreq )   //Hz, Peripheral frequince CCLK/1
     #define PCLK2         ( CCLKfreq/2 ) //Hz, Peripheral frequince CCLK/2
     #define PCLK4         ( CCLKfreq/4 ) //Hz, Peripheral frequince CCLK/4

      #define PCLK7        (( Fpclk / 16 ) / 9600) ;  /*baud rate */

     #define PCLK6         ( CCLKfreq/6 ) //Hz, Peripheral frequince CCLK/6 only for CAN
     #define PCLK8         ( CCLKfreq/8 ) //Hz, Peripheral frequince CCLK/8
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/



/****************************************************************************************************/
/*                          P E R I P H E R A L    C L K    S E T I N G                             */
/****************************************************************************************************/
  #define PCLKwdt       ( PCLK4 )      //Hz, Peripheral clock for WDT
  #define PCLKt0        ( PCLK1 )      //Hz, Peripheral clock for TIMER0
  #define PCLKt1        ( PCLK4 )      //Hz, Peripheral clock for TIMER1
  #define PCLKu0        ( PCLK4 )      //Hz, Peripheral clock for UART0
  #define PCLKu1        ( PCLK4 )      //Hz, Peripheral clock for UART1
  #define PCLKpwm1      ( PCLK4 )      //Hz, Peripheral clock for PWM1
  #define PCLKi2c0      ( PCLK4 )      //Hz, Peripheral clock for I2C0
  #define PCLKspi       ( PCLK4 )      //Hz, Peripheral clock for SPI
  #define PCLKrtc       ( PCLK4 )      //Hz, Peripheral clock for RTC, except PCLK1
  #define PCLKssp1      ( PCLK4 )      //Hz, Peripheral clock for SSP1
  #define PCLKdac       ( PCLK4 )      //Hz, Peripheral clock for DAC
  #define PCLKadc       ( PCLK4 )      //Hz, Peripheral clock for ADC
  #define PCLKcan1      ( PCLK4 )      //Hz, Peripheral clock for CAN1, except PCLK8
  #define PCLKcan2      ( PCLK4 )      //Hz, Peripheral clock for CAN2, except PCLK8
  #define PCLKacf       ( PCLK4 )      //Hz, Peripheral clock for ACF, except PCLK8
  #define PCLKbram      ( PCLK4 )      //Hz, Peripheral clock for BAT RAM
  #define PCLKgpio      ( PCLK4 )      //Hz, Peripheral clock for GPIO
  #define PCLKpcb       ( PCLK4 )      //Hz, Peripheral clock for PCB
  #define PCLKi2c1      ( PCLK4 )      //Hz, Peripheral clock for I2C1
  #define PCLKssp0      ( PCLK4 )      //Hz, Peripheral clock for SSP0
  #define PCLKt2        ( PCLK4 )      //Hz, Peripheral clock for TIMER2
  #define PCLKt3        ( PCLK4 )      //Hz, Peripheral clock for TIMER3
  #define PCLKu2        ( PCLK4 )      //Hz, Peripheral clock for UART2
  #define PCLKu3        ( PCLK4 )      //Hz, Peripheral clock for UART3
  #define PCLKi2c2      ( PCLK4 )      //Hz, Peripheral clock for I2C2
  #define PCLKi2s       ( PCLK4 )      //Hz, Peripheral clock for I2S
  #define PCLKmci       ( PCLK4 )      //Hz, Peripheral clock for MCI
  #define PCLKscon      ( PCLK4 )      //Hz, Peripheral clock for SYSCON
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/


/****************************************************************************************************/
/*                P E R I P H E R A L    P O W E R   C O N T R O L   S E T I N G                    */
/****************************************************************************************************/
  #define pT0           ( DIS  << 1  )    //TIMER0   power control bit
  #define pT1           ( DIS << 2  )    //TIMER1   power control bit
  #define pU0           ( EN  << 3  )    //UART0    power control bit
  #define pU1           ( EN << 4  )    //UART1    power control bit
  #define pPWM1         ( DIS << 6  )    //PWM1     power control bit
  #define pI2C0         ( EN << 7  )    //I2C0     power control bit
  #define pSPI          ( DIS << 8  )    //SPI      power control bit
  #define pRTC          ( EN  << 9  )    //RTC      power control bit
  #define pSSP1         ( DIS << 10 )    //SSP1     power control bit
  #define pEMC          ( DIS << 11 )    //EMC      power control bit
  #define pADC          ( EN << 12 )    //ADC      power control bit
  #define pCAN1         ( DIS << 13 )    //CAN1     power control bit
  #define pCAN2         ( DIS << 14 )    //CAN2     power control bit
  #define pI2C1         ( DIS << 19 )    //I2C1     power control bit
  #define pSSP0         ( DIS << 21 )    //SSP0     power control bit
  #define pT2           ( EN << 22 )    //TIMER2   power control bit
  #define pT3           ( DIS << 23 )    //TIMER3   power control bit
  #define pU2           ( EN << 24 )    //UART2    power control bit
  #define pU3           ( EN << 25 )    //UART3    power control bit
  #define pI2C2         ( DIS << 26 )    //I2C2     power control bit
  #define pI2S          ( DIS << 27 )    //I2S      power control bit
  #define pSD           ( DIS << 28 )    //SD/MMC   power control bit
  #define pGPDMA        ( DIS << 29 )    //GP DMA   power control bit
  #define pENET         ( DIS << 30 )    //Ethernet power control bit
  #define pUSB          ( DIS << 31 )    //USB      power control bit
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/



/****************************************************************************************************/
/*                                  S C S    D E F I N I S I O N                                    */
/****************************************************************************************************/
  #define scsGPIOM     ( fastP0_P1 )   //
  #define scsEMCR      ( EMCrstOff )   //???????????????????????????????????????????????????????
  #define scsMCIPWR    ( MCIPhigh )    //
  #if OSCfreq>15000000
               #define scsOSCRNG    ( OSC_15_24mhz ) //
     #else
               #define scsOSCRNG    ( OSC_1_20mhz ) //
  #endif
  #if CLKsrc == OSCsrc
               #define scsOSCEN     ( OCSen )       //
     #else
               #define scsOSCEN     ( OCSdis ) //
  #endif
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/

/****************************************************************************************************/
/*                            C L K S R C S E L    D E F I N I S I O N                              */
/****************************************************************************************************/
 #define CLKSRCSELdef  ( CLKsrc )
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/





/****************************************************************************************************/
/*                              L O W L E V E L    D E F I N I S I O N                              */
/****************************************************************************************************/
#include "pclkselCalc.h"
  #define PCLKSEL0def ( PCS01def|PCS02def )
  #define PCLKSEL1def ( PCS11def|PCS12def )
 // #define PCP1def   ( pT0|pT1|pU0|pU1|pPWM1|pI2C0|pSPI|pRTC|pSSP1|pEMC|pADC|pCAN1|pCAN2|pI2C1|pSSP0 )
  //#define PCP2def   ( pT2|pT3|pU2|pU3|pI2C2|pI2S|pSD|pGPDMA|pENET|pUSB )
  #define PCP1def   ( pT0|pT1|pU0|pU1|pPWM1|pI2C0|pSPI|pRTC|pSSP1|pEMC|pADC|pCAN1|pCAN2|pI2C1|pSSP0 )
  #define PCP2def   ( pT2|pT3|pU2|pU3|pI2C2|pI2S|pSD|pGPDMA|pENET|pUSB )
  #define PCONPdef  ( PCP1def|PCP2def )
  #define SCSdef     ( scsGPIOM|scsEMCR|scsMCIPWR|scsOSCRNG|scsOSCEN )

/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/



















/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/



 #endif
#endif